package day03.loader;

/**
 * @Auther: Min.Liu
 * @Description:
 * @Date: Created in 9:52 2025/4/18
 */
public class LoadPractise {
    public static void main(String[] args) {
        //Singleton.test();
        Singleton.getInstance();
    }

    private static void test1() {
        System.out.println(E.a);
        System.out.println(E.b);
        System.out.println(E.c);
        System.out.println(new E());
    }
}
class E {
    public static final int a = 10;
    public static final String b = "hello";
    public static final Integer c = 20;
    static{
        System.out.println("静态初始化！");
    }
    {
        System.out.println("普通初始化！");
    }
}

class Singleton {

    public static void test() {
        System.out.println("test");
        System.out.println(LazyHolder.s);
    }

    private Singleton() {}

    //类是懒惰加载的  在他的被访问前 他是不会被加载的
    private static class LazyHolder{
        private static final Singleton SINGLETON = new Singleton();
        private static final String s = "测试";
        static {
            System.out.println("lazy holder init");
        }
    }

    public static Singleton getInstance() {
        return LazyHolder.SINGLETON;
    }
}
